/*
 * ContainerEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import com.cute4j.swing.Component;
import com.cute4j.swing.Container;

/**
 * Container Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class ContainerEvent extends ComponentEvent {

// Public Static Fields. -------------------------------------------------------

  /**
   * Component added id.
   */
  public static final int COMPONENT_ADDED = 300;

  /**
   * Component removed id.
   */
  public static final int COMPONENT_REMOVED = 301;

// Public Static Fields. -------------------------------------------------------

  private static final long serialVersionUID = -4881001767695946865L;

// Private Fields. -------------------------------------------------------------

  private final transient Component child;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new FocusEvent object.
   *
   * @param source the source container of the event
   * @param id the event id
   * @param child the child component
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   * @throws IllegalArgumentException if the child is <tt>null</tt>
   */
  public ContainerEvent(Container source, int id, Component child) {
    super(source, id);
    if (child == null) {
      throw new IllegalArgumentException("Null child");
    }
    this.child = child;
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the source container of the event.
   *
   * @return the source container of the event
   */
  public Container getContainer() {
    return (Container)source;
  }

  /**
   * Returns the component that was added or removed.
   *
   * @return the component that was added or removed
   */
  public Component getChild() {
    return child;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String paramString() {
    String idString;
    switch(getID()) {
      case COMPONENT_ADDED:
        idString = "COMPONENT_ADDED";
        break;
      case COMPONENT_REMOVED:
        idString = "COMPONENT_REMOVED";
        break;
      default:
        idString = "unknown type";
    }
    return idString + ",child=" + child.getName();
  }

}
